package dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import dao.AreaDao;
import dao.RowMapper;
import entity.Area;

public class AreaDaoImpl implements AreaDao {
	private JDBCTemplate jdbc = new JDBCTemplate();
	
	private class RowMapperImpl implements RowMapper<Area>{

		@Override
		public Area rowMapper(ResultSet rs) throws SQLException {
			return new Area(rs.getInt("areaId"), rs.getString("areaName"), null);
		}
		
	}
	
	@Override
	public List<Area> queryAllArea() {
		String sql = "SELECT * FROM `area`";
		return jdbc.queryAll(sql, new RowMapperImpl());
	}

	@Override
	public Area queryAreaByAreaId(int areaId) {
		String sql = "SELECT * FROM `area` WHERE areaId=?";
		return jdbc.queryOne(sql, new RowMapperImpl(), areaId);
	}

}
